#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>


using namespace std;

class Node {
public:
    int val;
    Node* left;
    Node* right;
    Node* next;

    Node() : val(0), left(NULL), right(NULL), next(NULL) {}

    Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}

    Node(int _val, Node* _left, Node* _right, Node* _next)
        : val(_val), left(_left), right(_right), next(_next) {}
};

class Solution {
public:
    Node* connect(Node* root) {
        if(root==nullptr){
            return nullptr;
        }
        helper(root->left,root->right);
        return root;
    }
    void helper(Node* l,Node* r){
        if(l==nullptr||r==nullptr) return;
        l->next=r;
        helper(l->left,r->right);
        helper(r->left,r->right);
        helper(l->right,r->left);
    }
};

int main(){




    return 0;
}